package risk.control.project.service;


import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;
import risk.control.project.entity.repository.BranchBean;
import risk.control.project.framework.PostService;
import risk.control.project.mapper.branch.BranchMapper;

import java.util.HashMap;
import java.util.List;

/**
 * 网点信息
 */
@Service
public class BranchService extends PostService {

    @Qualifier("MainSqlSessionFactory")
    private final SqlSessionFactory sqlSessionFactory;

    @Qualifier("JedisPool")
    private final JedisPool jedisPool;

    public BranchService(JedisPool jedisPool, SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
        this.jedisPool = jedisPool;
    }

    /**
     * 查询网点列表
     *
     * @return String
     */
    public String queryBranchList() {
        try (SqlSession session = sqlSessionFactory.openSession(true)) {
            HashMap<String, String> params = new HashMap<>();
            BranchMapper mapper = session.getMapper(BranchMapper.class);
            List<BranchBean> branchList = mapper.queryBranch();
            return generateSucceed(branchList);
        }
    }
}
